/******************************************************************************\
    String.h contains functions for working with strings.
    Copyright (C) 2008  Victor Vinogradov (fly3333@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
\******************************************************************************/

#ifndef StringH
#define StringH

#include <vector>
#include <string>
#include <cstdarg>
#include <map>
#include <Common\Memory.hpp>
#include "KMP.h"

class cCIKMPString
{
	std::string String;
	cMemory< int > Next;
public:
	cCIKMPString( const char str[] )
		: String( str )
		, Next( strlen( str ) + 1 )
	{
		PreCIKMP( String.c_str(), ( int )String.length(), Next );
	}
	cCIKMPString( const std::string &str )
		: String( str )
		, Next( str.length() + 1 )
	{
		PreCIKMP( String.c_str(), ( int )String.length(), Next );
	}
	cCIKMPString( const cCIKMPString &kmp_string )
		: String( kmp_string.String )
		, Next( kmp_string.Next )
	{
	}
	cCIKMPString &operator =( const cCIKMPString &kmp_string )
	{
		String = kmp_string.String;
		Next = kmp_string.Next;
		return *this;
	}
	int FindIn( const char str[], int str_length ) const 
	{
		return CIKMP( str, str_length, String.c_str(), ( int )String.length(), Next );
	}
	int Length() const
	{
		return ( int )String.length();
	}
};

std::vector< std::string > Split( const std::string &src, const std::string &separator );
std::vector< std::string > SplitCI( const std::string &src, const std::string &separator );
std::string Trim( const std::string &str );
std::string Concat( const std::vector< std::string > &strings, const std::string &separator = "" );
std::string Concat( std::vector< std::string >::const_iterator begin, std::vector< std::string >::const_iterator end, const std::string &separator );
std::string ToLower( const std::string &str );
std::string ToUpper( const std::string &str );
std::vector< std::string > Trim( const std::vector< std::string > &v );
std::string Trim( const std::string &str, const std::string &trimer );
std::string StringPrintfV( const char *format, va_list arg_list );
std::string StringPrintf( const char *format, ... );
std::string IpAddress( unsigned long ip );
std::string IpAddressPort( unsigned long ip, unsigned short port );
std::string EscapeFileName( const std::string &file_name );
std::string UrlDecode( const std::string &url );
std::map< std::string, std::string > SplitParameters( const std::string &parameters );
std::vector< std::string > SplitQuoted( const std::string &source, const std::string &separator, const std::vector< std::string > &opening_quote, const std::vector< std::string > &closing_quote );
//std::vector< std::string > GetCommandLineArguments();
std::vector< std::string > SkipWhite( const std::vector< std::string > &source, const std::string &white );
bool Cut( std::string &str, const cCIKMPString &beginstr, const cCIKMPString &endstr );
std::string RandomString( unsigned length );
std::string UrlEncode( const std::string &src );
std::string ConvertCodePage( const std::string &source_string, unsigned source_codepage, unsigned destination_codepage );
std::string Base64Encode( const std::string &src );

#endif
